package com.chanzany.singleton.type8;


public class SingletonTest {
    public static void main(String[] args) throws InterruptedException {
//        for (int i = 0; i < 1000; i++) {
//            new Thread(()->{
//                Singleton instance = Singleton.getInstance();
//            }).start();
//        }
        Singleton instance = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance.hashCode()==instance2.hashCode());
    }
}

/**
 * 懒汉式（枚举）
 * 枚举类型是线程安全的，并且只会装载一次
 */
enum Singleton{
    INSTANCE;
    public static Singleton getInstance(){
        return INSTANCE;
    }
}